<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>todolist代办事项</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<link rel="stylesheet" type="text/css" href="css/animate.min.css" />
		<script src="js/lcXys.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<style>
			.footer {
			
				width: 300px;
				/* background: #000; */
				position: fixed;
				left: 725px;
				bottom: 20px;
				color: grey;
				font-weight: bold;
			}
			.footer p {
				height: 34px;
				line-height: 34px;
				cursor: pointer;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<div class="main">
				<div class="header">
					<div class="logo">Today-Todo</div>
					<!-- 绑定回车事件,v-model绑定输入框的value值 -->
					<input type="text" id="input" v-model="inputValue" placeholder="请输入代办事项" @keydown.enter="enterEvent" />
				</div>
				<div class="doing todo">
					<h3><span class="title">正在进行</span><span class="num">{{doningLength}}</span></h3>
					<div class="list">
						<transition-group name="slide" mode="out-in" enter-active-class="animated bounceInLeft" leave-active-class="animated bounceOutRight">
							<div class="todoItem" v-for="item,index in doingList" :key="index">
								<input @click.prevent="checkDone(item.id)" :data-id="item.id" type="checkbox">
								<div class="content">{{item.content}}</div>
								<div class="del" @click="deleteItem(item.id)">删除</div>
							</div>
							</transition-group>
					</div>
				</div>
				<div class="done todo">
					<h3><span class="title">已经完成</span><span class="num">{{doneLength}}</span></h3>
					<div class="list">
						<transition-group name="slide" enter-active-class="animated bounceInLeft" leave-active-class="animated bounceOutRight">
							<div class="todoItem" v-for="item,index in doneList" :key="'done'+index">
								<input @click.prevent="checkDone(item.id)" :data-id="item.id" type="checkbox" checked="checked">
								<div class="content">{{item.content}}</div>
								<div class="del" @click="deleteItem(item.id)">删除</div>
							</div>
							</transition-group>
					</div>
				</div>
			</div>
			<div class="footer">
				<p v-if="!isShow" @click="Contact">WeChat:homexjh</p>
				<p v-if="isShow" @click="Contact">Welocome to contact me</p>
			</div>
		</div>
		<script type="text/javascript">
			let vm = new Vue({
				el: "#app",
				data: {
					todoList: [],
					inputValue: "",
					isShow:true
				},
				computed: {
					//通过过滤todolist数据，得到未做好的列表和已做好的列表
					doingList: function() {
						let arr = this.todoList.filter(function(item, index) {
							return !item.isDone
						})
						return arr;
					},
					doneList: function() {
						let arr = this.todoList.filter(function(item, index) {
							return item.isDone
						})
						return arr;
					},
					doningLength:function() {
						return this.doingList.length;
					},
					doneLength:function() {
						return this.doneList.length;
					}
				},
				methods: {
					enterEvent: function(event) {
						console.log("444444");
						//将数据添加到todoList上
						this.todoList.push({
							content: this.inputValue,
							isDone: false,
							id:this.todoList.length
						})
						console.log(this.todoList.length)
						//保存数据
						this.saveData()
						//清空输入框的值
						this.inputValue = "";
					},
					//将数据保存到本地存储
					saveData: function() {
						localStorage.todoList = JSON.stringify(this.todoList)
					},
					checkDone:function(id) {
						this.todoList[id].isDone = !this.todoList[id].isDone;
						//每次操作都要修改
						this.saveData()
					},
					deleteItem:function(id) {
						this.todoList.splice(id,1)
						this.todoList.forEach(function(item,i) {
							item.id = i;
						})
						this.saveData()
					},
					Contact:function(){
						this.isShow = !this.isShow
					}
				},
				mounted:function(){
					this.todoList = localStorage.todoList?JSON.parse(localStorage.todoList):[];
				}
			})
		</script>
	</body>
</html>
